const app = require('../app')
const { NAME_OR_PASSWORD_IS_REQUEIRED, NAME_IS_ALREADY_EXIT, NAME_IS_NOT_EXIT, PASSWORD_IS_INCORRECT, UNAUTHPRIZATION, OPTION_IS_NOT_ALLOW } = require('../config/error')
app.on('error', (error, ctx) => {
    let code = 0
    let message = ''

    switch (error) {
        case NAME_OR_PASSWORD_IS_REQUEIRED:
            code = -1001
            message = '用户名或密码不为空'
            break
        case NAME_IS_ALREADY_EXIT:
            code = -1002
            message = '用户名已经存在，请更换'
            break
        case NAME_IS_NOT_EXIT:
            code = -1003
            message = '用户名不存在,请检查后输入'
            break
        case PASSWORD_IS_INCORRECT:
            code = -1004
            message = '密码不正确，请检查后重新输入'
            break
        case UNAUTHPRIZATION:
            code = -1005
            message = '无效的token或者token已经过期'
            break
        case OPTION_IS_NOT_ALLOW:
            code = -2001
            message = '没有权限操作~'
            break
    }
    ctx.body = { code, message }
})